version: '3.8'
services:
  db:
    container_name: project_data_base
    image: postgres:latest
    restart: always
    env_file: ./.env
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 5s
      retries: 5
    environment:
      - POSTGRES_USER=$POSTGRESDB_USER
      - POSTGRES_PASSWORD=$POSTGRESDB_ROOT_PASSWORD
      - POSTGRES_DB=$POSTGRESDB_DATABASE
    ports:
      - $POSTGRESDB_LOCAL_PORT:$POSTGRESDB_DOCKER_PORT
    volumes:
      - project_volume:/var/lib/postgresql/data/
      - ./db/init.sql:/docker-entrypoint-initdb.d/create_tables.sql
  app:
    depends_on:
      - db
    build: ./atom-skills-app
    container_name: app_api
    restart: unless-stopped
    env_file: ./.env
    ports:
      - $NODE_LOCAL_PORT:$NODE_DOCKER_PORT
    environment:
      - DB_HOST=db
      - DB_USER=$POSTGRESDB_USER
      - DB_PASSWORD=$POSTGRESDB_ROOT_PASSWORD
      - DB_NAME=$POSTGRESDB_DATABASE
      - DB_PORT=$POSTGRESDB_DOCKER_PORT
    stdin_open: true
    tty: true
  client:
    build: ./atom-skills-client
    container_name: client_frontend
    ports:
      - $CLIENT_LOCAL_PORT:$CLIENT_DOCKER_PORT
    volumes:
      - ./client:/atom-skills-client
      - /atom-skills-client/node_modules
    env_file: ./.env
    stdin_open: true
    tty: true
volumes:
  project_volume:
    name: my_project_volume
